using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter10
{
	/// <summary>
	/// Example15: Energy and Atwood's Machine
	/// Consider two cylinder having different masses m_1 and m_2, 
	/// connected by a string passing over a pulley has a radius R 
	/// and moment of inertia I about its axis of rotation.
	/// The string does not slip on the pulley, and the system is 
	/// released from rest. Find the linear speeds of the cylinders 
	/// after cylinder 2 descends through a distance h, 
	/// and the angular speed of the pulley at this time.
	/// v_f = \sqrt{(2(m_2-m_1)gh)/(m_1+m_2+I/R^2)}
	/// </summary>
	public class Example15
	{
		public Example15()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			double g = L.Constant.AccelerationOfGravity;
			L.Length h = new L.Length();
			h.m = 2.0;
			L.Mass m1 = new L.Mass();
			m1.kg = 10.0;
			L.Mass m2 = new L.Mass();
			m2.kg = 40.0;
			L.KineticEnergy Ki = new L.KineticEnergy();
			Ki.J = 0.0;
			L.KineticEnergy Kf = new L.KineticEnergy();
			Kf.VariableQ = true;
			L.PotentialEnergy Ui = new L.PotentialEnergy();
			Ui.J = 0.0;
			L.PotentialEnergy Uf = new L.PotentialEnergy();
			Uf.J = m1.kg*g*h.m+m2.kg*g*(-h.m);
			L.FundamentalLaw.EnergyConservation(Ki,Ui,Kf,Uf);
			L.Mass effmass = new L.Mass();
			L.MomentOfInertia I = new L.MomentOfInertia();
			I.XX = 10.0;
			L.Length R = new L.Length();
			R.m = 2.0;
			effmass.kg = m1.kg + m2.kg + I.XX/R.m/R.m;
			L.Velocity vf = new L.Velocity(effmass,Kf);
            result += Convert.ToString(vf.mPERs)+"\r\n";
			result += Convert.ToString(Math.Sqrt((2.0*(m2.kg-m1.kg)*g*h.m)
				/(m1.kg+m2.kg+I.XX/R.m/R.m)));
		}
	}
}
